package cn.le.webSocket;


import cn.le.service.DeviceDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@Component
public class DeviceDateHandler extends TextWebSocketHandler {

    @Autowired
    private DeviceDateService deviceDateService;

    /**
     * 打开会话
     * @param session
     */

    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        deviceDateService.onOpen(session);
    }

    /**
     * 关闭会话
     * @param session
     */
    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        deviceDateService.onClose(session);
    }

    /**
     * 异常处理
     * @param session
     * @param
     */
    @Override
    public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
        deviceDateService.onError(session,exception);
    }
}
